Machines are usually designed to complete or facilitate tasks for us. Once up and running, they are doomed to perform what ever they were constructed for. Also, the machine T2 executes the function assigned to it, but the sole purpose of this machine is to switch itself off again - “I would prefer not to”.
T2 is an homage to the mathematician Claude Elwood Shannon and a simplified interpretation of his "ultimate machine".
Here´s a link to the Wikipedia article on Claude Elwood Shannon
and of course the code - even if it´s only one servo
#include <VarSpeedServo.h>
//Servo VarSpeedServomyservo; // create variable speed servo object
// this constant won't change const int switchPin = 6; // Pinnumber ON/OFF Switch
// Variables will change: int switchState = 0; // current state of the ON/OFF Switch int lastswitchState = 0; // previous state of the ON/OFF Switch
void setup() {
pinMode(switchPin, INPUT); // initialize the ON/OFF Switch pin as a input myservo.attach(10, 1, 255); // attaches the variable speed servo on pin 9 to the servo object myservo.write(180); }
void loop() {
switchState = digitalRead(switchPin); // read the state of the ON/OFF Switch value
// compare the buttonState to its previous state if (switchState != lastswitchState) { if (switchState == HIGH) { // if the switchState is HIGH delay(225); // wait myservo.write(40); // move Servo to position at full speed delay400); lastswitchState = switchState; } else { // if it is, the switchState is LOW myservo.slowmove(180, 50); // move Servo to position left at variable speed lastswitchState = switchState; } } }